import request from "../utils/request"
import qs from "qs"
/*
    用于发送网络请求的api
*/

// const URL_BASE = 'http://159.75.128.32:5000'
const axios = (
  url,
  data = {},
  method = "POST",
  headers = { "Content-Type": "application/json" },
  isToken = true
) => request({ url, data, method, headers, isToken })

// 获取验证码
export const reqCode = () =>
  axios("/auth/verifiCode/code", {}, "GET", {}, false)

//登录账号
export const reqLogin = (data) => {
  data = qs.stringify(data)
  return axios(
    "/auth/oauth/token",
    data,
    "POST",
    { "Content-Type": "application/x-www-form-urlencoded" },
    false
  )
}

export const reqLogout = () => axios("/auth/oauth/logout", {}, "get")

//获取IP地址
export const reqIP = () =>
  axios(
    `https://restapi.amap.com/v3/ip?key=876f95acbc748e5d60b4adaa0124efa9`,
    {},
    "GET",
    {},
    false
  )

//根据IP地址获取天气信息
export const reqWeather = (city = "九江") =>
  axios(
    `https://restapi.amap.com/v3/weather/weatherInfo?key=876f95acbc748e5d60b4adaa0124efa9&city=${city}`,
    {},
    "GET",
    {},
    false
  )

// 新建分类列表
export function insertList(data) {
  return axios(`/grid/gridcenter/communityVenue/insert`, data)
}

// 获取文化馆列表
export function getList(data) {
  return axios(`/grid/gridcenter/communityVenue/list`, data)
}
// 获取文化馆时段列表
export function getHourList(data) {
  return axios(`/grid/gridcenter/communityVenueTime/list`, data)
}

// 获取分类详情
export function getDetail(id) {
  return axios(
    "/grid/gridcenter/communityVenue/detail",
    qs.stringify({ id }),
    "post",
    { "Content-Type": "application/x-www-form-urlencoded" }
  )
}
// 修改分类列表
export function updateList(value) {
  return axios('/grid/gridcenter/communityVenue/update', value)
}

// 删除分类列表
export function deleteList(id) {
  return axios(
    "/grid/gridcenter/communityVenue/delete",
    qs.stringify({ id }),
    "post",
    { "Content-Type": "application/x-www-form-urlencoded" }
  )
}
